package ar.edu.itba.it.paw.web.user;

import java.util.List;

import org.apache.wicket.behavior.SimpleAttributeModifier;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.PropertyListView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.spring.injection.annot.SpringBean;

import ar.edu.itba.it.paw.domain.User;
import ar.edu.itba.it.paw.repo.UserRepo;
import ar.edu.itba.it.paw.web.MercadoLibreSession;
import ar.edu.itba.it.paw.web.base.BasePage;

public class LastLoginPage extends BasePage{
	
	@SpringBean
	UserRepo userRepo;
	
	public LastLoginPage(){
		
		if(!MercadoLibreSession.get().getUser().isAdmin()){
			setResponsePage(UserMenuPage.class);
			return;
		}
		
		IModel<List<User>> userModel = new LoadableDetachableModel<List<User>>() {
			@Override
			protected List<User> load() {
				return userRepo.getAllUsers();
			}
		};
		
		
		add(new PropertyListView<User>("lastLogin", userModel) {
			
			@Override
			protected void populateItem(ListItem<User> item) {
				item.add(new Label("username",new PropertyModel<User>(item.getModel(), "username")).add(new SimpleAttributeModifier("style", "color: #00FFFF")));
				item.add(new Label("first_name",new PropertyModel<User>(item.getModel(), "first_name")).add(new SimpleAttributeModifier("style", "")));
				item.add(new Label("last_name",new PropertyModel<User>(item.getModel(), "last_name")).add(new SimpleAttributeModifier("style", "")));
				item.add(new Label("date",new PropertyModel<User>(item.getModel(), "last_login")).add(new SimpleAttributeModifier("style","color: #FFFF00")));
			}
		});
	}
}
